﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using IMDemo.Models;

namespace IMDemo.Views
{
    /// <summary>
    /// UCContactList.xaml 的交互逻辑
    /// </summary>
    public partial class UCContactList : UserControl
    {
        private ObservableCollection<ContactModel> contactList;

        public ObservableCollection<ContactModel> ContactList
        {
            get
            {
                if (this.contactList == null)
                {
                    this.contactList = new ObservableCollection<ContactModel>();
                }

                return this.contactList;
            }
        }

        private ContactModel selectedContact;

        public ContactModel SelectedContact
        {
            get
            {
                return this.selectedContact;
            }

            set
            {
                this.selectedContact = value;
            }
        }

        public UCContactList()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        private void btnSendMessage_Click(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;
            this.OnSendMessage((ContactModel)btn.Tag);
        }

        #region 自定义事件
        public delegate void SendMessageHandle(object sender, ContactModel to);

        public event SendMessageHandle SendMessage;

        public void OnSendMessage(ContactModel to)
        {
            if (this.SendMessage != null)
            {
                this.SendMessage(this, to);
            }
        }
        #endregion
    }
}
